package com.aishua.andpaydemo.utils;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by aishua on 2018/4/2.
 */

public class DeviceInfosynUtils {

    private static LinkedHashMap<String, String> linkedHashMap;

    public static String parmToJson(String sequenceid, String TargetNum) {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("Req_SequenceID", sequenceid);
            jsonObject.put("OpType", 3);
            if (null == TargetNum || "0".equals(TargetNum))
                return jsonObject.toString();
            Iterator iter = linkedHashMap.entrySet().iterator();
            while (iter.hasNext()) {
                Map.Entry entry = (Map.Entry) iter.next();
                String key = (String) entry.getKey();
                String val = (String) entry.getValue();
                jsonObject.put(key, val);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return jsonObject.toString();
    }

//      public String jsonToparm(String result) throws JSONException {
//
//           JSONObject jsonObject = new JSONObject(result);
//
//
//
//      }

    public void getStrFromMap(int targetNum, List<String> Block_id) {

        linkedHashMap.clear();
        linkedHashMap = new LinkedHashMap<>();
        for (int i = 0; i < targetNum; i++) {
            String key;
            if (i < 10) {

                key = "IoT_ID_0" + i + 1;
            } else {
                key = "IoT_ID_" + i + 1;
            }
            linkedHashMap.put(key, Block_id.get(i));
        }
    }
}



